#include <bits/stdc++.h>
using namespace std;
using ll = long long;



void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i]; if(a[i] == 1) a[i] = 2;
    }
    map<int, int> mp;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        ans += mp[a[i]];
        mp[a[i]]++;
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--) solve();
    return 0;
}